package com.ocean.recommendationserver.realtimerecommend.result;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一API响应结果封装
 *
*/
@Data
@NoArgsConstructor
public class Result<T> extends ResultData {

    private static final long serialVersionUID = 1L;

    private int errcode = 500;
    private String errmsg = null;
    private T content;

    private Result(T content) {
        this.setSuccess(true);
        this.errcode = 0;
        this.content = content;
    }

    private Result(int errcode, String errmsg) {
        this.errcode = errcode;
        this.errmsg = errmsg;
        this.setSuccess(false);
    }


    /**
     * 判断返回是否为成功
     *
     * @param content
     * @return 是否成功
     */
    public static <T> Result<T> success(T content) {
        return new Result<>(content);
    }


    /**
     * 判断返回是否为成功
     *
     * @param  errcode
     * @param errmsg
     * @return 是否成功
     */
    public static <T> Result<T> failure(int errcode,String errmsg) {
        return new Result<>(errcode, errmsg);
    }

}
